package my.jwds.p94;


import java.util.ArrayList;
import java.util.List;

public class InorderTraversal {

    public static void main(String[] args) {
        TreeNode node = TreeNode.to_binaryHaveNull(new Integer[]{1,null,2});
        System.out.println(node);


        InorderTraversal o = new InorderTraversal();
        TreeNode treeNode = TreeNode.to_binary(new int[]{3,2,3});
        System.out.println(o.inorderTraversal(treeNode));
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if (root != null){
            if (root.left != null){
                res.addAll(inorderTraversal(root.left));
            }
            res.add(root.val);
            if (root.right != null){
                res.addAll(inorderTraversal(root.right));
            }

        }
        return res;
    }
}
